<?php

namespace App\Http\Requests\Api\Article;

use App\Http\Requests\Api\BaseRequest;
use Illuminate\Validation\Rule;

/**
 * Class 文章列表搜索
 * @package App\Http\Requests\Api\Article
 */
class IndexRequest extends BaseRequest
{

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array
	 */
	public function rules()
	{
		return [
//			'category'   => [function ($attribute, $value, $fail){
//					if($value){
//					    return Category::find($value) ? true : $fail('分类不存在s');
//					}
//			},],

			'category' =>'nullable|string|exists:category,id',
			'size'       => 'nullable|min:1|max:50',
			'title'      => 'nullable|string|max:30',
			'author'     => 'nullable|string|max:30',
			'order'      => [
				'nullable',
				Rule::in(['created', 'sort'])
			],
			'sort'       => [
				'nullable',
				Rule::in(['asc', 'desc'])
			],
			'start_time' => '',
			'end_time'   => '',
		];
	}

	public function attributes()
	{
		return [
			'category' => '分类',
			'size'     => '分页大小',
			'title'    => '标题',
			'author'   => '作者',
			'order'    => '排序选项',
			'sort'     => '排序顺序',
		];
	}

	public function messages()
	{
		return [
			'category.exists' => '查询的分类不存在',
			'order.in'        => '排序选项不在范围内',
			'sort.in'         => '排序顺序不在范围内',
		];
	}
}
